import torch

# scalar, 0D, rank 0
tensor0d = torch.tensor(1)
print("tensor0d .dtype", tensor0d.dtype)

# vector, 1D, rank 1
# if we create tensors from python floats, pytorch create tensors with 32-bit precision by default.
# this choice is primarily due to the balance precision and computational efficiency
tensor1d = torch.tensor([1.0, 2.0, 3.0])
print("tensor1d .dtype", tensor0d.dtype)

tensorFloat64 = tensor1d.to(torch.float64)
print("tensor1d .to(float64)", tensorFloat64.dtype)

# matrix, 2D, rank2
tensor2d = torch.tensor([[1, 2, 3], [4, 5, 6]])
print("tensor2d .dtype", tensor0d.dtype)
float_tensor2d = tensor2d.to(torch.float32)
print("float tensor2d .dtype", float_tensor2d.dtype)

# multi-matrix, 3D, rank3, 2-row, 2-col, 2-depth
tensor3d = torch.tensor([
    [[1, 2], [3, 4]],
    [[5, 6], [7, 8]]
])
print("tensor3d .dtype", tensor0d.dtype)
print(tensor3d)
